package bankowosc.polaczenie;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import bankowosc.dane.Waluta;

public class WalutaBD {

	public ArrayList<Waluta> pobierzWalute(polacz p) {
		ArrayList<Waluta> waluty = new ArrayList<>();
		Statement stmt = p.getStmt();
		String komenda = "select * from waluta";
		try {
			ResultSet rs = stmt.executeQuery(komenda);
			while(rs.next()) {
				waluty.add(new Waluta(rs.getInt(1),rs.getString(2),rs.getString(3),
						rs.getFloat(4),rs.getString(5)));
			}
			rs.close();
			return waluty;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
        public Waluta pobierzWaluteRachunku(polacz p, int id) {
		Waluta w = null;
		Statement stmt = p.getStmt();
		String komenda = "select * from waluta where id_waluty="+id;
		try {
			ResultSet rs = stmt.executeQuery(komenda);
			while(rs.next()) {
				w=(new Waluta(rs.getInt(1),rs.getString(2),rs.getString(3),
						rs.getFloat(4),rs.getString(5)));
			}
			rs.close();
			return w;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
        
}
